
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import template
import root.utils.DBQuery as DBQuery
from root.utils.htmlbuilder import htmlbuilder
from root import application as app
import os

'''Event Objects will be passed in the form of Arrays of event objects
     [Event 1, Event 2, Event 3] where 
     Event 1 etc = [Event Name, EventLink, Location, Event Pic URL, AgeLimit, VIP, Start_time, Date, Promoted]
'''
    

class VenuePage(webapp.RequestHandler):
    
      
    '''
     get function for generating page for a specific day
    '''
    def get(self):
        
        venuelist = DBQuery.DBQuery()
        venues = venuelist.query_venue()
        builder = htmlbuilder()
        htmlpage = builder.gen_venues(venues)
        self.response.out.write(htmlpage)

    '''
     Post function for generating page for a specific day
    '''
    def post(self):
        venuelist = DBQuery.DBQuery()
        venues = venuelist.query_venue()
        
        if venues == "None" :
                 
            path = os.path.join(os.path.dirname(app.__file__), 'html/NoResultsFound.html')
            self.response.out.write(template.render(path,''))
            self.response.out.write("""No Results Found. <p> <input type = "image" src = "../images/back_button.png" class = "button_top_left" value = "Back" onClick = "history.go(-1);return true;"> </p>""")
        else:
            builder = htmlbuilder()
            htmlpage = builder.gen_venues(venues)
            self.response.out.write(htmlpage)
                        

application = webapp.WSGIApplication([('/venues', VenuePage)], debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()
